package testMagic;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import junit.framework.TestCase;
import org.junit.*;

import magic.MagicController;
import player.*;

public class testMagicController extends TestCase{
	
	@Test
	public void testPickMagicCard_0(){ //By default, player has the magic card zero
		//Since player cannot own the same card, it must be return false;
		Player p = new Player();
		MagicController mC = new MagicController(p);
		int actual = mC.pickMagicCard(1);
		assertEquals(0, actual);
	}
	
	@Test 
	public void testPickedMagicCard_1(){
		//Remove the default Magic Card, so it can be added
		Player p = new Player();
		p.setMagicCards(0, false);
		MagicController mC = new MagicController(p);
		int actual = mC.pickMagicCard(1);
		assertEquals(1, actual);
	}
	
	@Test 
	public void testMagicController_1() throws Exception{
		//Remove the default Magic Card, so it can be added
		String data = "\n";
		
		InputStream testInput = new ByteArrayInputStream( data.getBytes("UTF-8") );
		InputStream old = System.in;
		int actual;
		
		try {
		    System.setIn( testInput );
		    Player p = new Player();
			MagicController mc = new MagicController(p);
			actual = mc.RandomCards();
		} finally {
		    System.setIn( old );
		}
		
		assertEquals(1, actual);
	}
}
